********************************************************************************
** 	TITLE:   f4_summary_stats.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Table VI: Summary Statistics, Main Analysis Sample

********************************************************************************
		set sortseed 13
		
		use "$output_data/estimate.dta", replace
		keep if !mi(dow_scheduled)
		qui reg D_ignite_proxy //create an empty estimation table
		eststo summ_stats
		
			//stay ignite_0 for Recidivism
				cap drop stay
				gen stay = stay_rec
				cap drop ignite_0
				gen ignite_0 = ignite_0_rec
				
		foreach v in $auxiliary_control age_65plus D_remove_any D_felony ignite_0 ///
			stay D_maj return_3m return_6m return_9m return_12m num_c ///
			D_health prison D_incident D_convicted {
			
			su `v' if `v'>=0
			local `v'sd: di %8.3f r(sd)
			local `v'sd = subinstr("("+"``v'sd'"+")"," ","",.)
			local `v'count: di %9.0gc r(N)
			local `v': di %8.3f r(mean) 
			local `v'_sum = "``v''"+"&"+"``v'sd'"+"&"+"``v'count'"
			
			estadd local `v'_sum "``v'_sum'": summ_stats

		}		
		
		estout summ_stats ///
					using "$tables/summ_stats.tex", style(tex)  ///
					label nobaselevels collabels(none) mlabels(none) /// 
					drop(_cons) ///
					cells(b(star fmt(%8.3f)) se(par fmt(%8.3f))) /// 
					starlevels(* 0.10 ** 0.05 *** 0.01) /// 
					stats(foo ///
							D_remove_any_sum ignite_0_sum stay_sum ///
							return_3m_sum ///
							D_convicted_sum ///
							prison_sum ///
							D_maj_sum D_health_sum D_incident_sum ///
							foo foo ///
							D_female_sum age_17_24_sum age_25_34_sum age_35_44_sum age_45_54_sum age_55_64_sum ///
							age_65plus_sum D_Black_sum prior_offense_1y_sum D_felony_sum num_c_sum ///
							foo foo ///
							pctebll_sum pc_black_sum pc_hs_sum log_med_hhincome_sum D_missing_sum ///
							, /// 
						labels("\textbf{Panel A: Instrument and Outcomes}" ///
						"Any District Court Delay" ///
						"Months in IGNITE" "Months in Jail" ///
						"Ever Rebooked in 3 Months after Release" ///
						"Convicted" ///
						"Sentenced to Prison" ///
						"Any Major Misconduct"  "Any Medical or Suicidal Incident" ///
						"Any Incident" ///
						"\vspace{-.4cm} "  "\textbf{Panel B: Individual and Case Characteristics}" ///
						"Female" "Age 18-24" "Age 25-34" "Age 35-44" "Age 45-54" "Age 55-64" "Age 65+" ///
						"Black" "Booked in Past Year" "Felony Charge" "Number of Charges" ///
						"\vspace{-.4cm} " "\textbf{Panel C: Census Tract Characteristics}" ///
						"Share with Elevated Blood Lead Level"  ///
						"Share Black" "Share High School Graduate or Higher" ///
						"Log Median Household Income"  "Missing Census Tract Information" ///
						 )) replace